package com.ad.pet.app.mall;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.ad.pet.DaggerMainActivityCompent;
import com.ad.pet.MainActivity;
import com.ad.pet.R;
import com.ad.pet.app.Navigation;
import com.ad.pet.app.mall.adapter.FlashBuyAdapter;
import com.ad.pet.common.structure.mvp.BasePresenter;
import com.ad.pet.common.structure.ui.activity.AppToolbarActivity;
import com.ad.pet.models.remote.CommList;
import com.ad.pet.models.remote.User;
import com.ad.pet.models.remote.cart.Good;
import com.ad.pet.models.remote.mall.ProductDetail;
import com.ad.pet.models.remote.mall.Rating;
import com.ad.pet.models.remote.mall.Record;
import com.ad.pet.ui.SimpleDividerDecoration;

import java.util.List;

import javax.inject.Inject;

import butterknife.BindView;

/**
 * Created by SEELE on 2019/7/12.
 */

public class FlashBuyActivity extends AppToolbarActivity implements MallContracts.View{

    @Inject
    MallPresenter mMallPresenter;

    @BindView(R.id.recycler_list)
    RecyclerView mRecyclerList;
    private FlashBuyAdapter mFlashBuyAdapter;

    @Override
    protected void init(Bundle savedInstanceState) {
        super.init(savedInstanceState);
        mToolbar.setTitle(getString(R.string.flash_by));
    }

    @Override
    protected int contentLayout() {
        return R.layout.activity_flash_buy_list_good;
    }

    @Override
    protected void clickRetry(View v) {

    }

    @Override
    protected void initViews() {

        mFlashBuyAdapter = new FlashBuyAdapter(null);
        mRecyclerList.setLayoutManager(new LinearLayoutManager(mActivity));
        mRecyclerList.addItemDecoration(new SimpleDividerDecoration(mActivity,8,R.color.bg_color));
        mRecyclerList.setAdapter(mFlashBuyAdapter);
    }

    @Override
    protected void initData() {

        mMallPresenter.onCreate(this);

        mMallPresenter.getFlashList();
    }

    @Override
    protected void initEvents() {

        mFlashBuyAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                if (!hasLogin()){
                    Navigation.goLogin(mActivity,12,34);
                    return;
                }
                Navigation.goCommonWebView(mActivity,"","/event/rushbuy?pid="+mFlashBuyAdapter.getData().get(position).getProduct_id(),false,false, MainActivity.REQUEST_GO_MALL);
            }
        });
    }

    @Override
    public void initInject() {
        DaggerMainActivityCompent.builder().applicationComponent(getApplicationComponent()).activityModule(getActivityModule()).build().inject(this);
    }

    @Override
    protected BasePresenter getPresenter() {
        return mMallPresenter;
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void error(String msg) {

    }

    @Override
    public void error(int code, String msg) {

    }

    @Override
    public void getGoodDetailSuceess(ProductDetail productDetail) {

    }

    @Override
    public void getRateListSuccess(List<Rating> ratings) {

    }

    @Override
    public void getSaleRecordSuccess(List<Record> records) {

    }

    @Override
    public void addToCartSuccess(User i) {

    }

    @Override
    public void getFlashListSuccess(CommList<List<Good>> commList) {

        mStatusLayoutManager.showContent();
        mFlashBuyAdapter.setNewData(commList.getList());
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (data == null)
            return;
        switch (requestCode) {

            case MainActivity.REQUEST_GO_MALL:
                setResult(RESULT_OK, new Intent());
                finish();

                break;

        }
    }
}
